﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Input;
using System.Xml.Serialization;

namespace SQLDeployAnything.Data.Environment
{
    [Serializable]
    [XmlRoot(ElementName="Environment")]
    public class Environment : INotifyPropertyChanged
    {
        private string mName;
        private ObservableCollection<Connection> mConnections;

        public Environment()
        {
            mConnections = new ObservableCollection<Connection>();
            createCommands();
        }
        
        public string Name { get { return mName; } 
            set 
            {
                if (value != mName)
                {
                    mName = value;
                    OnPropertyChanged("Name");
                }
            } 
        }

        public ObservableCollection<Connection> Connections
        {
            get { return mConnections; }
            set 
            { 
                mConnections = value;
                OnPropertyChanged("Connections");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected internal void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(name));
        }

        [XmlIgnore]
        public ICommand AddConnection
        {
            get;
            internal set;
        }

        private void createCommands()
        {
            AddConnection = new Commands.CreateConnection(this);
        }

    }
}
